#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(){
	int n;
	cin >> n;
	vector<int> v(n);
	for(int& p : v)
		cin >> p;

	if(n > 15){
		map<int,int> mp;
		for(const int& p : v)
			mp[p]++;

		ll ans = 0;
		for(const pair<int,int>& p : mp)
			ans += 1LL * p.first * (p.second - 1);

		cout << ans << '\n';

		return;
	}

	int m = 1 << n, ans = 0;
	for(int i = 0; i < m; i++){
		int res = 0;
		bool flag[2] = {0};
		for(int j = 0; j < n; j++){
			if(flag[i >> j & 1]){
				for(int k = j - 1; k >= 0; k--){
					if((i >> k & 1) == (i >> j & 1)){
						if(v[k] == v[j])
							res += v[k];
						break;
					}
				}
			}
			flag[i >> j & 1] = 1;
		}
		ans = max(ans, res);
	}

	cout << ans << '\n';
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);

	int t;
	cin >> t;
	while(t--)
		solve();

	return 0;
}